// var i;
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_CurrencyData = require("./AL_GAME_HUA_CurrencyData");
// var f = cc._decorator;
// var d = f.ccclass;
// var h =
//     (f.property,
//     f.menu,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.icon = null;
//             t.label = null;
//             t.button = null;
//             t.label_time = null;
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.onLoad = function () {
//             var e = this;
//             if (AL_GAME_HUA_GameConst.GameConst.getInstance().vit_enabled) {
//                 this.icon = this.node.getChildByName("gold");
//                 this.label = this.node.getChildByName("label_number").getComponent(cc.Label);
//                 this.label_time = this.node.getChildByName("label_time").getComponent(cc.Label);
//                 this.button = this.node.getChildByName("addgoldbtn");
//                 var t = AL_GAME_HUA_CurrencyData.CurrencyData.getInstance();
//                 AL_APP_SDK_MANAGER.on(
//                     AL_GAME_HUA_Define.GameEvent.ON_VIT_CHANGE,
//                     function () {
//                         e.label.string = t.getHave(AL_GAME_HUA_CurrencyData.CurrencyType.VIT).toString();
//                     },
//                     this
//                 );
//                 this.label.string = t.getHave(AL_GAME_HUA_CurrencyData.CurrencyType.VIT).toString();
//             }
//         };
//         t.prototype.onDestroy = function () {
//             AL_APP_SDK_MANAGER.off(this);
//         };
//         t.prototype.update = function () {
//             if (AL_GAME_HUA_GameConst.GameConst.getInstance().vit_enabled) {
//                 var e = AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().jiancha_tili_zhi();
//                 e.progress >= 1
//                     ? (this.label_time.string = "Max")
//                     : (this.label_time.string = AL_GAME_HUA_Common.Common.geshihua_shijian(e.value, !1));
//             }
//         };
//         t.prototype.handle_event_click_button_add = function () {
//             AL_GAME_HUA_AddPrefab.AddPrefab.create_add_vit();
//         };
//         return __decorate([d], t);
//     })(cc.Component));
// exports.default = h;


const addPrefab = require("./AL_GAME_HUA_AddPrefab");
const common = require("./AL_GAME_HUA_Common");
const define = require("./AL_GAME_HUA_Define");
const gameConst = require("./AL_GAME_HUA_GameConst");
const currencyData = require("./AL_GAME_HUA_CurrencyData");
const { ccclass, property, menu } = cc._decorator;

/**
 * @class VitManager
 * @extends {cc.Component}
 * @classdesc 管理体力的类，负责体力显示和操作
 */
@ccclass
@menu("Game/VitManager")
class VitManager extends cc.Component {
    /** @type {cc.Node} */
    icon = null;

    /** @type {cc.Label} */
    label = null;

    /** @type {cc.Button} */
    button = null;

    /** @type {cc.Label} */
    label_time = null;

    /**
     * 加载时的初始化操作
     */
    onLoad() {
        if (gameConst.GameConst.getInstance().vit_enabled) {
            this.icon = this.node.getChildByName("gold");
            this.label = this.node.getChildByName("label_number").getComponent(cc.Label);
            this.label_time = this.node.getChildByName("label_time").getComponent(cc.Label);
            this.button = this.node.getChildByName("addgoldbtn");

            const currencyInstance = currencyData.CurrencyData.getInstance();

            AL_APP_SDK_MANAGER.on(
                define.GameEvent.ON_VIT_CHANGE,
                () => {
                    this.label.string = currencyInstance.getHave(currencyData.CurrencyType.VIT).toString();
                },
                this
            );

            this.label.string = currencyInstance.getHave(currencyData.CurrencyType.VIT).toString();
        }
    }

    /**
     * 销毁时的清理操作
     */
    onDestroy() {
        AL_APP_SDK_MANAGER.off(this);
    }

    /**
     * 每帧更新操作
     * @param {number} dt - 时间增量
     */
    update(dt) {
        if (gameConst.GameConst.getInstance().vit_enabled) {
            const vitStatus = currencyData.CurrencyData.getInstance().jiancha_tili_zhi();
            this.label_time.string = vitStatus.progress >= 1 ? "Max" : common.Common.geshihua_shijian(vitStatus.value, false);
        }
    }

    /**
     * 处理添加体力按钮点击事件
     */
    handle_event_click_button_add() {
        addPrefab.AddPrefab.create_add_vit();
    }
}

exports.default = VitManager;
